package org.yelongframework.excel.data.collect.sheet.mode.simple;

import org.yelongframework.excel.cell.ExcelCell;
import org.yelongframework.excel.data.SheetData;
import org.yelongframework.excel.data.SheetDatas;
import org.yelongframework.excel.data.collect.sheet.SheetDataCollectException;
import org.yelongframework.excel.row.ExcelRow;
import org.yelongframework.excel.sheet.ExcelSheet;

/**
 * 默认实现
 * 
 * @since 1.0.0
 */
public class DefaultSimpleSheetDataCollector extends AbstractSimpleSheetDataCollector {

	@Override
	protected SheetDatas doCollect(ExcelSheet excelSheet, SimpleSheetDataCollectScheme sheetDataCollectScheme)
			throws SheetDataCollectException {
		int rowIndex = sheetDataCollectScheme.getRowIndex();
		int colIndex = sheetDataCollectScheme.getColIndex();
		Object cellValue = getCellValue(excelSheet, rowIndex, colIndex);
		return new SheetDatas(excelSheet.getSheetIndex(), new SheetData(rowIndex, colIndex, cellValue));
	}

	protected Object getCellValue(ExcelSheet excelSheet, int rowIndex, int colIndex) {
		ExcelRow row = excelSheet.getRow(rowIndex);
		if (null == row) {
			return null;
		}
		ExcelCell cell = row.getCell(colIndex);
		if (null == cell) {
			return null;
		}
		return cell.getValueString();
	}

}
